﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using System.Web.Configuration;
using GNSCore.Model;
using GNSCore.Repositories.IOC;
using GNSCore.Services.UnityAdapters;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace GNSCore.Services.Contracts
{
    public class UnityServiceHost : ServiceHost
    {
        public UnityServiceHost(Type serviceType, Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
        }

        public UnityServiceHost(object singletonInstance, Uri[] baseAddresses)
            : base(singletonInstance, baseAddresses)
        {
        }

        protected override void InitializeRuntime()
        {
            //VirtualPathExtension extension = Extensions.Find<VirtualPathExtension>();
            //Configuration config = WebConfigurationManager.OpenWebConfiguration(extension.VirtualPath);
            //IUnityContainer container = new UnityContainer();
            //UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");
            //section.Containers.Default.Configure(container); 
            //UnityConfigurator.ChangeLifetime(LifetimeType.PerWebRequest);
            IOCManager.ConfigureContainer(new GNSDBEntities());
            Extensions.Add(new UnityExtension(IOCManager.IOCContainer));
            base.InitializeRuntime();
        }
    }
}
